﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WHM3
{
    public class LoginDetails
    {
        public bool isAuthenticated;
        public String ID;
        public bool isAdmin;
        public bool isManager;
        public bool checkedIntoWork;

        public LoginDetails(String ID,bool isAdmin,bool isManager)
        {
            this.isAuthenticated = true;
            this.ID = ID;
            this.isAdmin = isAdmin;
            this.isManager = isManager;
            this.checkedIntoWork = isCheckedIntoWork();
        }

        public bool isCheckedIntoWork()
        {
            string now = DateTime.Now.Day.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Year.ToString()
                + "::" + DateTime.Now.Hour + ":" + DateTime.Now.Minute.ToString();

            LinkedList<Shift> shifts = null;
            try
            {
                shifts = BL.getAllShiftsByIdAndDate(this.ID, Utils.getddmmyyyy(Utils.formatDate(now)));
            }
            catch
            {
                return false;
            }
            if (shifts.Count == 0)
            {
                //first shift of the day!
                return false;
            }

            LinkedListNode<Shift> node = shifts.First;
            Shift lastShift = node.Value;
            if (lastShift.Start != null && lastShift.End == "")
            {
                return true;
            }
            return false;
        }

    }
}